<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <base target="_self">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache,must-ridate">
    <meta http-equiv="expires" content="0">
    <title></title>
    <link rel="stylesheet" type="text/css" href="/static/plugins/bootstrap/css/bootstrap.min.css" />
</head>

<style  type="text/css">
    .required {
        color: red;
    }       
</style>

<body>
    <div style="height: 20px; text-align: right;">
        <button type="button" onclick="javascript:onSave();" class="btn blue">保 存</button>&nbsp;&nbsp;
    </div>

    <ul id="myTab" class="nav nav-tabs">
        <li class="active">
            <a href="#productInfo" data-toggle="tab">
               产品信息要素
            </a>
        </li>	
    </ul>

    <div id="myTabContent" class="tab-content">
        <div class="tab-pane fade in active" id="productInfo">
            <div style="height:390px;overflow-y:auto">
                <table border="1" bordercolor="#C0C0C0" cellspacing="0" cellpadding="2" style="width: 100%;">
                    <tr id="trtrust">
                        <td style="width: 20%;">
                            <span class="required">*</span>办理日期:
                        </td>
                        <td style="width: 30%;">
                            <input type="date" id="handledate" name="handledate" style="width: 320px;">
                        </td>
                        <td style="width: 20%;">
                            <span class="required">*</span>事前报告反馈日期:
                        </td>
                        <td style="width: 30%;">
                            <input type="date" id="overdate" name="overdate" style="width: 320px;">
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 20%;">
                            <span class="required">*</span>信托产品名称:
                        </td>
                        <td style="width: 30%;">
                            <input type="text" id="xtxmmc" name="xtxmmc" style="width: 320px;">
                        </td>					
                        <td style="width: 20%;">
                            <span class="required">*</span>信托登记系统产品编码:
                        </td>
                        <td style="width: 30%;">
                            <input type="text" id="djcpbh" name="djcpbh" style="width: 320px;">
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <span class="required">*</span>信托财产性质标识:
                        </td>
                        <td>
                            <select id="csxtcclx" name="csxtcclx" style="width: 320px;">
                                <option value="0">资金</option>
                                <option value="1">财产权</option>
                                <option value="2">混合</option>
                            </select>
                        </td>					
                        <td>
                            <span class="required">*</span>单一集合标识:
                        </td>
                        <td>
                            <select id="dyjhbz" name="dyjhbz" style="width: 320px;">
                                <option value="0">单一</option>
                                <option value="1">集合</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <span class="required">*</span>是否关联交易:
                        </td>
                        <td colspan="3">
                            <input type="radio" name="sfgljy" value="1" />是
                            <input type="radio" name="sfgljy" value="0" />否
                        </td>
					</tr>
					<tr>
                        <td>
                            <span class="required">*</span>事前报告事项原因:
                        </td>
                        <td colspan="3">
							<textarea cols="100" rows="5" id="sqbgyy" name="sqbgyy" style="width:800px;"></textarea>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <span class="required">*</span>信托经理姓名:
                        </td>
                        <td>
                            <input type="text" id="xtjlxm" name="xtjlxm" style="width: 320px;">
                        </td>					
                        <td>
                            <span class="required">*</span>信托经理电话:
                        </td>
                        <td>
                            <input type="text" id="xtjldh" name="xtjldh" style="width: 320px;">
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <span class="required">*</span>分管高级管理人员姓名:
                        </td>
                        <td colspan="3">
                            <input type="text" id="fggjglry" name="fggjglry" style="width: 320px;">
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>

    <script type="text/javascript" src="/static/plugins/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="/static/plugins/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript">

        //初始化数据
        let ydjData = new Object();
        $(function () {
            //获取流程参数
            let flowid = GetQueryValue('flowid');
            let itemid = GetQueryValue('itemid');
			let taskid = GetQueryValue('taskid');
			let nextnode = GetQueryValue('nextnode');
			if(nextnode=="X644307B0B24442290B4A6BAED269009"){
				jQuery("#trtrust").show();
			}else{
				jQuery("#trtrust").hide();
			}
            if (taskid == null) {
                itemid = "1@@"+itemid;
            } else {
                itemid = "2@@"+taskid;
            }
            find_app_dfs_zxd_sqcpxx_regitem_id(flowid, itemid);
        });

        //查询预登记-产品信息要素
        function find_app_dfs_zxd_sqcpxx_regitem_id(flowid, itemid) {
            //根据项目ID采集现有信息
            jQuery.ajax({
                data: { "flowid": flowid, "itemid": itemid },
                url: "/node/find_app_dfs_zxd_sqcpxx_regitem_id/" + itemid,
                async: false,
                cache: false,
                success: function (data) {
                    ydjData = data;
                    if (data.sfgljy == "1") {
                        $("input[name='sfgljy'][value=1]").attr("checked", true);
                    } else {
                        $("input[name='sfgljy'][value=0]").attr("checked", true);
                    }
                    $("#sqbgyy").val(data.sqbgyy);
					$("#handledate").val(data.handledate);
					$("#overdate").val(data.overdate);
                    $("#xtxmmc").val(data.xtxmmc);
                    $("#djcpbh").val(data.djcpbh);
                    $("#csxtcclx").val(data.csxtcclx);
                    $("#dyjhbz").val(data.dyjhbz);
                    $("#xtjlxm").val(data.xtjlxm);
                    $("#xtjldh").val(data.xtjldh);
                    $("#fggjglry").val(data.fggjglry);
                }
            });
        }
		//设置text,textarea和select对应值
		function setFormValue(name,value){
			$('#'+name).val(value);
		}
		
		//设置Radio对应值
		function setRadioValue(name,value){
			if(value==""){
				$("input[name="+name+"]").prop("checked",false);
			}else{
				$("input[name="+name+"][value="+value+"]").attr("checked", true);
			}
		}
		
		//设置Box对应值
		function setBoxValue(name,content){	
			if(content.indexOf('No,')>=0)
			{
				content=content.replace('No,','');
				let returnValue = content.split(",");
				$.each(returnValue, function (index, value) {
					$("#"+name+value).attr("checked",false)
				});
			}else{
				let returnValue = content.split(",");
				$.each(returnValue, function (index, value) {
					$("#"+name+value).attr("checked",true)
				});			
			}
		}
		
		//获取text,textarea和select对应值
		function getFormValue(name){
			let value = $('#'+name).val();
			return value;
		}
		
		//获取Radio对应值
		function getRadioValue(name){
			let value = $("input[name="+name+"]:checked").val();
			return value;
		}
		
		//获取Box对应值
		function getBoxValue(name){
			let value = $("input:checkbox[name="+name+"]:checked");
            let chvalue = [];
            $.each(value, function () {
                chvalue.push($(this).val());
            });
            value = chvalue.join(",");
			return value;
		}
		
		//日期格式化处理
		Date.prototype.Format = function(fmt)  
		{ 
			var o = {  
				"M+" : this.getMonth()+1,         //月份  
				"d+" : this.getDate(),          //日  
				"h+" : this.getHours(),          //小时  
				"m+" : this.getMinutes(),         //分  
				"s+" : this.getSeconds(),         //秒  
				"q+" : Math.floor((this.getMonth()+3)/3), //季度  
				"S" : this.getMilliseconds()       //毫秒  
			};  
			if(/(y+)/.test(fmt))  
				fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));  
			for(var k in o)  
				if(new RegExp("("+ k +")").test(fmt))  
			fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));  
			return fmt;  
		}

        
        //字段必输项+内容大小限制校验
		function checkInfo(name,content,flag,type){
			if(type=='text') value = getFormValue(name);
			else if(type=='box') value = getBoxValue(name);
			else if(type=='radio') value = getRadioValue(name);
			else value = getFormValue(name);
			if(flag=="required")
			{
				if(typeof(value)=="undefined" || value==null || value.length==0  || value.length==''){
					alert("字段["+content+"]为必填项!");
					//$("input[name="+name+"]").focus();
					document.getElementById(name).focus();
					return false;
				}
			}else if(flag=="length"){
				if(!(typeof(value)=="undefined" || value==null || value.length==0  || value.length=='') && value.length>type){
					alert("字段["+content+"]内容超过最大限制!");
					//$("input[name="+name+"]").focus();
					document.getElementById(name).focus();
					return false;
				}			
			}else if(flag=="number"){
				if(!(typeof(value)=="undefined" || value==null || value.length==0  || value.length=='')){
					var typeValue=type.split(",");
					if(value.indexOf(".")<0) value=value+'.00';
					var contentValue=value.split(".");
					if(contentValue[0].length > (typeValue[0]-typeValue[1]) || contentValue[1].length > typeValue[1]){
						alert("字段["+content+"]内容超过最大限制!");
						//$("input[name="+name+"]").focus();
						document.getElementById(name).focus();
						return false;
					}					
				}			
			}
			return true;
		}			
		//保存之前必输项校验
		function logicCheck(){
			let nextnode = GetQueryValue('nextnode');
			if(nextnode=="X644307B0B24442290B4A6BAED269009")
			{
				//if(!checkInfo('handledate','办理日期','required','text')) return false;
				//if(!checkInfo('overdate','事前报告反馈日期','required','text')) return false;
			}
			if(!checkInfo('xtxmmc','信托产品名称','required','text')) return false;
			if(!checkInfo('djcpbh','信托登记系统产品编码','required','text')) return false;
			if(!checkInfo('csxtcclx','信托财产性质标识','required','text')) return false;
			if(!checkInfo('dyjhbz','单一集合标识','required','text')) return false;
			if(!checkInfo('sfgljy','是否关联交易','required','radio')) return false;
			if(!checkInfo('sqbgyy','事前报告事项原因','required','text')) return false;
			if(!checkInfo('xtjlxm','信托经理姓名','required','text')) return false;
			if(!checkInfo('xtjldh','信托经理电话','required','text')) return false;
			if(!checkInfo('fggjglry','分管高级管理人员姓名','required','text')) return false;
			if(!checkInfo('xtxmmc','信托登记系统产品编码','length','50')) return false;
			if(!checkInfo('djcpbh','信托产品名称','length','50')) return false;
			if(!checkInfo('sqbgyy','事前报告事项原因','length','3000')) return false;
			if(!checkInfo('xtjlxm','信托经理姓名','length','50')) return false;
			if(!checkInfo('xtjldh','信托经理电话','length','50')) return false;
			if(!checkInfo('fggjglry','分管高级管理人员姓名','length','50')) return false;
			return true;
		}
        
        //事前报告信息保存
        function onSave() {
			//保存校验
			if(!logicCheck()){
				return false;	
			}		
            //产品信息要素
            ydjData.sfgljy = $("input[name='sfgljy']:checked").val();
            ydjData.sqbgyy = $("#sqbgyy").val();
			ydjData.handledate = $("#handledate").val();
			ydjData.overdate = $("#overdate").val();
            ydjData.xtxmmc=$("#xtxmmc").val();
            ydjData.djcpbh=$("#djcpbh").val();
            ydjData.csxtcclx=$("#csxtcclx").val();
            ydjData.dyjhbz=$("#dyjhbz").val();
            ydjData.xtjlxm=$("#xtjlxm").val();
            ydjData.xtjldh=$("#xtjldh").val();
            ydjData.fggjglry=$("#fggjglry").val();
            jQuery.ajax({
                //请求方式
                type: "POST",
                //请求地址
                url: "/node/insert_app_dfs_zxd_sqcpxx",
                //数据，json对象
                data: ydjData,
                //请求成功
                success: function (data) {
                    alert("保存成功！");
                },
                //请求失败，包含具体的错误信息
                error: function (e) {
                    alert("保存失败！");
                    console.log(e.status);
                    console.log(e.responseText);
                }
            });
        }

        //获取GET参数
        function GetQueryValue(queryName) {
            var query = decodeURI(window.location.search.substring(1));
            var vars = query.split("&");
            for (var i = 0; i < vars.length; i++) {
                var pair = vars[i].split("=");
                if (pair[0] == queryName) { return pair[1]; }
            }
            return null;
        }
		//事前报告填报说明
        function inputContent(){
			window.open('/node/tianbao.html?type=4','_blank','');
		}		
    </script>
</body>

</html>